// FrogImageResizeDialog.cpp : Implementation of CFrogImageResizeFastDialog

#include "stdafx.h"
#include "FrogImageResizeFastDialog.h"
#include "FrogMessageBox.h"


// CFrogImageResizeFastDialog
CFrogImageResizeFastDialog::CFrogImageResizeFastDialog(HICON hIcon):
CFrogProgressReportDialog(hIcon),
m_Folder(L"Resized Images"),
m_ShrinkBy(0.5),
m_SaveJPG(false),
m_PutInFolder(true)
{
}

LRESULT CFrogImageResizeFastDialog::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	CFrogProgressReportDialog::OnInitDialog(uMsg, wParam, lParam, bHandled);

	m_EditFolder.Attach(GetDlgItem(IDC_EDIT_FOLDER));
	m_CheckBoxPutInFolder.Attach(GetDlgItem(IDC_CHECK_PUT_IN_FOLDER));

	if (!m_PutInFolder)
	{
		m_EditFolder.EnableWindow(FALSE);
	}

	DoDataExchange(FALSE);

	return 0;
}

LRESULT CFrogImageResizeFastDialog::OnClickedOk(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	bHandled = TRUE;
	// TODO: Add your control notification handler code here
	DoDataExchange(TRUE);

	if (m_CheckBoxPutInFolder.GetCheck() == TRUE)
	{
		if (!FilerFrogUtils::IsFileNameValid(wstring(m_Folder)))
		{
			FrogMessageBox(m_hWnd, L"Please Enter a Valid Folder Name", L"FilerFrog - Image Resize", 0);
			return TRUE;
		}
	}
	else
	{
		m_Folder = L"";
	}

	RunAsyncCommandWithProgressBar(false);

	EndDialog(wID);
	return 0;
}

LRESULT CFrogImageResizeFastDialog::OnClickedCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	bHandled = TRUE;
	// TODO: Add your control notification handler code here
	DoDataExchange(TRUE);

	m_Folder = L"";

	EndDialog(wID);
	return 0;
}

LRESULT CFrogImageResizeFastDialog::OnCheckPutInFolderBnClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	if (m_CheckBoxPutInFolder.GetCheck())
	{
		m_EditFolder.EnableWindow(TRUE);
	}
	else
	{
		m_EditFolder.EnableWindow(FALSE);
	}

	return 0;
}

void CFrogImageResizeFastDialog::ExecuteCommand()
{
	m_FilesRefactor.ShrinkImageFilesByPercent(m_LastResult, m_FilesList, m_ShrinkBy, -1, m_SaveJPG, wstring(m_Folder));
}